# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgname=python2-poppler
_pkgname=pypoppler
pkgver=0.12.1
pkgrel=11
pkgdesc='Python 2.x bindings for Poppler.'
arch=('x86_64' 'aarch64')
url='https://launchpad.net/poppler-python'
license=('GPL')
depends=('pygtk' 'poppler-glib')
source=("https://launchpad.net/poppler-python/trunk/development/+download/$_pkgname-$pkgver.tar.gz"
        'pypoppler-0.12.1-poppler-0.16.0.patch'
        'python-poppler-0.12.1-poppler-0.39.0-changes.patch')
sha512sums=('04055411adc19f6af499a7cba0d6c5abb51e0802dd28962f833da3da1caf6ff274ff67d082f9c47548dac7a4ceb1bccf9860cda71fe48b8b7df74c0132498d20'
            '09cfe6b43382453974fb6aa9975cdb482f64f171698828f671bb309fbc085b530e8b222c43a80e0940a8f755540eb979a580e2b7c966d7cb158a4815787fa71f'
            'ac38068df3db8dc92c981e9e7c5f7de8c2e4fb47a39977b9bbb8e735a686a2e64a750ccb27158cc97b060d3c878be300b750505094e9cdf3c7e465b2cdfbf39f')

prepare() {
  cd "$_pkgname-$pkgver"

  # poppler 0.16 compat
  patch -Np0 -i ../pypoppler-0.12.1-poppler-0.16.0.patch

  # poppler 0.18 compat
  sed -i "/pixbuf/,/^)/d" poppler.defs

  # poppler 0.39 compat
  patch -Np0 -i ../python-poppler-0.12.1-poppler-0.39.0-changes.patch
}

build() {
  cd "$_pkgname-$pkgver"

  if [[ "$CARCH" == "x86_64" ]]; then
    ./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var \
      PYTHON=python2
  else
    ./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var \
      --build=arm PYTHON=python2
  fi

  make
}

package() {
  cd "$_pkgname-$pkgver"

  make DESTDIR="$pkgdir" install
}

